import 'package:flutter/material.dart';
import 'package:haokezufang/widgets/common_floating_action_bottom.dart';

import '../../../widgets/common_image_picker.dart';
import '../../../widgets/common_item_form.dart';
import '../../../widgets/common_radio_item.dart';
import '../../../widgets/common_select_form_item.dart';
import '../../../widgets/common_title.dart';
import '../../../widgets/room_appliance.dart';

class RoomAdd extends StatefulWidget {
  const RoomAdd({super.key});

  @override
  State<RoomAdd> createState() => _RoomAddState();
}

class _RoomAddState extends State<RoomAdd> {
  late int rentType = 0;
  int roomType = 0; // 户型

  var titleController = TextEditingController(); // 描述
  var descController = TextEditingController(); // 描述
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('房源发布'),
      ),
      body: ListView(
        children: [
          const CommonTitle(title: '房源信息'),
          CommonItemForm(
            label: '小区',
            contentBuilder: (context) => GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: () => Navigator.of(context).pushNamed('search'),
                child: const SizedBox(
                  height: 40,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [Text('请选择小区'), Icon(Icons.keyboard_arrow_right)],
                  ),
                )),
          ),
          CommonItemForm(
              label: '租金',
              suffixText: '元/月',
              hintText: '请输入租金',
              controller: TextEditingController()),
          CommonItemForm(
            label: '大小',
            suffixText: '平方米',
            hintText: '请输入房屋大小',
            controller: TextEditingController(),
          ),
          CommonRadioFormItem(
            label: '租凭方式',
            options: const ['合租', '整租'],
            value: rentType,
            onChange: (index) {
              setState(() => rentType = index!);
            },
          ),
          CommonSelectFormItem(
            label: '户型',
            value: roomType,
            onChange: (val) {
              setState(() => roomType = val!);
            },
            options: const ['一室', '二室', '三室', '四室'],
          ),
          const CommonTitle(title: '房源图像'),
          const CommonImagePicker(),
          const CommonTitle(title: '房源标题'),
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 10),
            child: TextField(
              controller: titleController,
              decoration: const InputDecoration(
                hintText: '请输入标题（例如：整组，小区名 2 室 2000 元）',
                border: InputBorder.none,
              ),
            ),
          ),
          const CommonTitle(title: '房源配置'),
          RoomAppliance(onChange: (data) {}),
          const CommonTitle(title: '房源描述'),
          Container(
            margin: const EdgeInsets.only(bottom: 100),
            padding: const EdgeInsets.symmetric(horizontal: 10),
            child: TextField(
              controller: descController,
              maxLines: 5,
              decoration: const InputDecoration(
                hintText: '请输入房屋描述信息',
                border: InputBorder.none,
              ),
            ),
          ),
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: CommomFloatingActionBottom(
        titleText: '发布',
        onClick: () {},
      ),
    );
  }
}
